package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.File;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.prefs.Preferences;

public class Main extends Application {

    static Stage stage;
    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("initial_scene.fxml"));
        primaryStage.setTitle("Magic Square Generator");
        stage = primaryStage;
        primaryStage.setScene(new Scene(root, 1320, 880));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }

    static void replaceSceneContent(String name) throws Exception {
        try {
            Parent page = FXMLLoader.load(Main.class.getResource(name));
            Scene scene = new Scene(page, 1320, 880);
            stage.setScene(scene);
            stage.sizeToScene();
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("页面加载异常！");
            //logger.log(Level.SEVERE, "页面加载异常！");
        }
    }

    public static Stage getPrimaryStage() {
        return stage;
    }

    public static void setPersonFilePath(File file) {
        Preferences prefs = Preferences.userNodeForPackage(Main.class);
        if (file != null) {
            prefs.put("filePath", file.getPath());
            // Update the stage title.
            stage.setTitle("Puzzle - " + file.getName());
        } else {
            prefs.remove("filePath");
            // Update the stage title.
            stage.setTitle("Puzzle");
        }
    }
}
